<?php

namespace App\Http\Controllers;

use App\AboutUs;
use App\Achievement;
use App\Banner;
use App\CharitableActivities;
use App\Classify;
use App\Comment;
use App\EnAboutUs;
use App\EnAchievement;
use App\EnApplicationField;
use App\EnBanner;
use App\EnCharitableActivities;
use App\EnComment;
use App\EnEnvironmentalProtectionKnowledge;
use App\EnFooterMenu;
use App\EnGoodsProduct;
use App\EnHumanResources;
use App\EnNews;
use App\EnPhilanthropy;
use App\EnProjectCases;
use App\EnSysInfo;
use App\EnvironmentalProtectionKnowledge;
use App\Http\Services\FileManager;
use App\News;
use App\Philanthropy;
use App\ProjectCases;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class EnHomeController extends Controller
{
    protected $enWebInfo    = null;//统一数据输出
    protected $title      = null;
    protected $enFooterMenu = null;//底部主要内容

    /**
     * 设置头部信息
     * @param $title
     */
    public function setTitle($title){
        $this->title = $title;
    }

    /**
     * 获取头部信息
     * @return null
     */
    public function getTitle(){
        return $this->title;
    }

    public function __construct(){
        $this->getEnWebInfo();
    }

    public function getEnWebInfo(){
        $webInfoArr = null;

        /** @var EnSysInfo $webInfo */
        $allEnWebInfo = EnSysInfo::all();
        if(count($allEnWebInfo) > 0){
            foreach($allEnWebInfo as $webInfo){
                switch($webInfo->type){
                    case 'title':
                        $webInfoArr['title'] = $webInfo->content;
                        break;
                    case 'desc':
                        $webInfoArr['desc'] = $webInfo->content;
                        break;
                    case 'keyword':
                        $webInfoArr['keyword'] = $webInfo->content;
                        break;
                    case 'record':
                        $webInfoArr['record'] = $webInfo->content;
                        break;
                    case 'logo':
                        $webInfoArr['logo_url'] = FileManager::getImgUrl((int)$webInfo->content);
                        break;
                    case 'url':
                        $webInfoArr['url'] = $webInfo->content;
                        break;
                    case 'footer':
                        $webInfoArr['footer_info'] = $webInfo->content;
                        break;
                }
            }
        }

        if(!is_null($this->getTitle())){
            $webInfoArr['title'] = $this->getTitle();
        }

        $bannerArr = array();
        /** @var EnBanner $banner */
        $default = '';
        $num     = 0;
        $allBanner = EnBanner::orderBy('sort','asc')->orderBy('created_at','desc')->get();
        if(count($allBanner) > 0){
            foreach($allBanner as $banner){
                $bannerUrl = FileManager::getImgUrl($banner->img_id);
                $banner->img_url = $bannerUrl;
                if(!$default){
                    $default = 'active';
                    $banner->item = $default;
                }

                $num++;
                $banner->num = $num - 1;

                array_push($bannerArr,$banner);
            }
        }

        $webInfoArr['banner'] = $bannerArr;

        $this->enWebInfo = $webInfoArr;

        //TODO 获取底部主要内容
        /** @var EnFooterMenu $footerMenu */
        $allEnFooterMenu = EnFooterMenu::wherePid(0)->orderBy('sort','asc')->orderBy('created_at','desc')->get();
        if(count($allEnFooterMenu) > 0){
            foreach($allEnFooterMenu as $footerMenu){
                $childFooterMenu = EnFooterMenu::wherePid($footerMenu->id)->orderBy('sort','asc')->orderBy('created_at','desc')->get();
                $footerMenu->child = $childFooterMenu;
            }
        }

        $this->enFooterMenu = $allEnFooterMenu;
    }


    public function enIndex(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        //公益理念
        /** @var EnPhilanthropy $philanthropy */
        $philanthropyList = EnPhilanthropy::orderBy('sort','asc')->take(4)->get();
        if(count($philanthropyList) > 0){
            foreach($philanthropyList as $philanthropy){
                $philanthropy->img_url = FileManager::getImgUrl($philanthropy->img_id);

                $philanthropy->desc = mb_strimwidth($philanthropy->desc,0,130,'...','utf-8');
            }
        }

        $classifyPhilanthropy = Classify::whereLanguageType('en')->whereType('philanthropy')->first();

        //环保知识
        $enviromentalIds = [];
        $environmentalClassifies = [(object)['name' => 'All','class_info' => '*','item' => 'btn_active']];
        $environmentalClassifyList = Classify::whereType('en_environmental')->orderBy('sort','asc')->get();
        if(count($environmentalClassifyList) > 0){
            foreach($environmentalClassifyList as $environmentalClassify){
                $classInfo = '';
                $childEnvironmentalList = EnEnvironmentalProtectionKnowledge::whereClassifyTwoId($environmentalClassify->id)->take(6)->get();
                if(count($childEnvironmentalList) > 0){
                    foreach($childEnvironmentalList as $childEnvironmental){
                        array_push($enviromentalIds,$childEnvironmental->id);

                        if($classInfo){
                            $classInfo = $classInfo . ', .' . $childEnvironmental->id;
                        }else{
                            $classInfo = '.' . $childEnvironmental->id;
                        }
                    }
                }else{
                    $classInfo = '.0';

                }

                $data = (object)['name' => $environmentalClassify->name,'class_info' => $classInfo,'item' => ''];

                array_push($environmentalClassifies,$data);
            }
        }

        /** @var EnEnvironmentalProtectionKnowledge $environmental */
        $environmentalList = EnEnvironmentalProtectionKnowledge::whereIn('id',$enviromentalIds)->orderBy('sort','asc')->orderBy('created_at','desc')->get();
        if(count($environmentalList) > 0){
            foreach($environmentalList as $environmental){
                $environmental->img_url = FileManager::getImgUrl($environmental->img_id);
            }
        }

        $classifyEnvironmental = Classify::whereLanguageType('en')->whereType('environmental_section')->first();

        //我们的成就
        /** @var EnAchievement $achievement */
        $achievementList = EnAchievement::orderBy('sort','asc')->take(4)->get();
        if(count($achievementList) > 0){
            foreach($achievementList as $achievement){
                $achievement->img_url = FileManager::getImgUrl($achievement->img_id);
            }
        }

        $classifyAchievement = Classify::whereLanguageType('en')->whereType('achievement')->first();

        //最新动态
        $newIds = array();
        $newsData = array();
        /** @var EnNews $news */
        $newsOne = EnNews::orderBy('sort','asc')->orderBy('created_at','desc')->first();
        if($newsOne){
            $oneTwo = EnNews::where('id','<>',$newsOne->id)->orderBy('sort','asc')->orderBy('created_at','desc')->first();
            if($oneTwo){
                $oneTwo->title = mb_strimwidth($oneTwo->title,0,71,'...','utf-8');
                $oneTwo->img_url = FileManager::getImgUrl($oneTwo->img_id);
                $oneTwo->desc = mb_strimwidth($oneTwo->desc,0,150,'...','utf-8');
                $newsData['news_two'] = $oneTwo;
                array_push($newIds,$oneTwo->id);
            }
            $newsOne->title = mb_strimwidth($newsOne->title,0,71,'...','utf-8');
            $newsOne->img_url = FileManager::getImgUrl($newsOne->img_id);
            $newsOne->desc = mb_strimwidth($newsOne->desc,0,150,'...','utf-8');
            $newsData['news_one'] = $newsOne;
            array_push($newIds,$newsOne->id);
        }

        $newsList = EnNews::whereNotIn('id',$newIds)->orderBy('sort','asc')->orderBy('created_at','desc')->take(5)->get();
        if(count($newsList) > 0){
            foreach($newsList as $news){
                $news->title = mb_strimwidth($news->title,0,25,'...','utf-8');
                $news->img_url = FileManager::getImgUrl($news->img_id);
                $news->desc = mb_strimwidth($news->desc,0,60,'...','utf-8');

            }
        }

        $newsData['news_three'] = $newsList;

        $classifyNews = Classify::whereLanguageType('en')->whereType('news')->first();

        //评论
        $commentNum = EnComment::count();
        $default = '';
        $commentPage = [];
        for($i = 0;$i < $commentNum / 2;$i++){
            if(!$default){
                $default = 'active';
                $commentPageData = (object)[
                    'num' => $i,
                    'item' => $default,
                ];
            }else{
                $commentPageData = (object)[
                    'num' => $i,
                    'item' => ''
                ];
            }

            array_push($commentPage,$commentPageData);
        }

        /** @var EnComment $comment */
        $commentList = EnComment::orderBy('sort','asc')->orderBy('created_at','desc')->get();
        $default = '';
        $num     = 0;
        if(count($commentList) > 0){
            foreach($commentList as $comment){
                $comment->photo_url = FileManager::getImgUrl($comment->photo_id);

                if(!$default){
                    $default = 'active';
                    $comment->item = $default;
                }

                $num++;
                $comment->num = $num - 1;
            }
        }

        $checkCommentList = array_chunk($commentList->toArray(),2);

        $classifyComment = Classify::whereLanguageType('en')->whereType('comment')->first();

        //项目案例
        /** @var EnProjectCases $projectCase */
        $projectCaseData = EnProjectCases::orderBy('sort','asc')->orderBy('created_at','desc')->take(3)->get();
        if(count($projectCaseData) > 0){
            foreach($projectCaseData as $projectCase){
                $projectCase->title   = mb_strimwidth($projectCase->title,0,48,'...','utf-8');
                $projectCase->img_url = FileManager::getImgUrl($projectCase->img_id);
                $projectCase->desc = mb_strimwidth($projectCase->desc,0,95,'...','utf-8');
            }
        }

        $classifyProjectCase = Classify::whereLanguageType('en')->whereType('project_case')->first();

        //公益活动
        /** @var EnCharitableActivities $charitable */
        $charitableData = EnCharitableActivities::orderBy('sort','asc')->orderBy('created_at','desc')->take(3)->get();
        if(count($charitableData) > 0){
            foreach($charitableData as $charitable){
                $charitable->title   = mb_strimwidth($charitable->title,0,48,'...','utf-8');
                $charitable->img_url = FileManager::getImgUrl($charitable->img_id);
                $charitable->desc = mb_strimwidth($charitable->desc,0,95,'...','utf-8');
            }
        }

        $classifyCharitable = Classify::whereLanguageType('en')->whereType('charitable')->first();

        $navSection = Classify::whereLanguageType('zh')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $classifyName = (object)['type' => 'home'];

        return view('en_index',[
            'select'                  => $select,
            'sectionList'             => $sectionList,
            'web_info'                => $this->enWebInfo,
            'en_footer_menu'          => $this->enFooterMenu,
            'philanthropyList'        => $philanthropyList,
            'classifyPhilanthropy'    => $classifyPhilanthropy,
            'achievementList'         => $achievementList,
            'classifyAchievement'     => $classifyAchievement,
            'environmentalList'       => $environmentalList,
            'environmentalClassifies' => $environmentalClassifies,
            'classifyEnvironmental'   => $classifyEnvironmental,
            'newsData'                => $newsData,
            'classifyNews'            => $classifyNews,
            'commentPage'             => $commentPage,
            'commentList'             => $commentList,
            'checkCommentList'        => $checkCommentList,
            'classifyComment'         => $classifyComment,
            'projectCaseData'         => $projectCaseData,
            'classifyProjectCase'     => $classifyProjectCase,
            'charitableData'          => $charitableData,
            'classifyCharitable'      => $classifyCharitable,
            'navSection'              => $navSection,
            'classifyName'            => $classifyName,
        ]);
    }

    public function enEnvironmentalList(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $classifyId = !is_null($request->get('classify_id')) ? $request->get('classify_id') : 0;
        if(!$classifyId){
            /** @var Classify $thisClassify */
            $thisClassify = Classify::whereType('en_environmental')->orderBy('sort','asc')->first();
            if($thisClassify){
                $classifyId = $thisClassify->id;
            }else{
                $classifyId = 0;
            }
        }

        $environmentalClassifyList = Classify::whereType('en_environmental')->orderBy('sort','asc')->get();

        /** @var EnEnvironmentalProtectionKnowledge $environmental */
        $environmentalList = EnEnvironmentalProtectionKnowledge::whereClassifyTwoId($classifyId)->orderBy('sort','asc')->orderBy('created_at','desc')->paginate(9);
        if(count($environmentalList) > 0){
            foreach($environmentalList as $environmental){
                $environmental->img_url = FileManager::getImgUrl($environmental->img_id);
            }
        }

        //满目名称
        $classifyName = Classify::whereLanguageType('en')->whereType('environmental_section')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-environmental-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'en_footer_menu' => $this->enFooterMenu,
            'environmentalClassifyList' => $environmentalClassifyList,
            'environmentalList' => $environmentalList,
            'classifyId' => $classifyId,
            'classifyName' => $classifyName
        ]);
    }

    public function enEnvironmentalDetail(Request $request){
        $select = 'en_index';
        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $environmental = EnEnvironmentalProtectionKnowledge::whereId($id)->first();
        if($environmental){
            $environmental->thumb_img_url = FileManager::getImgUrl($environmental->thumb_img_id);
        }

        //满目名称
        $classifyName = Classify::whereLanguageType('en')->whereType('environmental_section')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-detail',['select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'detail' => $environmental,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyName
        ]);
    }

    public function enNewsList(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $newsList = EnNews::orderBy('sort','asc')->orderBy('created_at','desc')->paginate(9);
        if(count($newsList) > 0){
            foreach($newsList as $news){
                $news->img_url = FileManager::getImgUrl($news->img_id);
            }
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('news')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-news-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'en_footer_menu' => $this->enFooterMenu,
            'newsList' => $newsList,
            'classifyName' => $classifyName
        ]);
    }

    public function enNewsDetail(Request $request){
        $select = 'en_index';
        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $news = EnNews::whereId($id)->first();
        if($news){
            $news->thumb_img_url = FileManager::getImgUrl($news->thumb_img_id);
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('news')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-detail',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'detail' => $news,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyName
        ]);
    }

    public function enProjectCaseList(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        /** @var EnProjectCases $projectCase */
        $projectCaseList = EnProjectCases::orderBy('sort','asc')->orderBy('created_at','desc')->paginate(9);
        if(count($projectCaseList) > 0){
            foreach($projectCaseList as $projectCase){
                $projectCase->img_url = FileManager::getImgUrl($projectCase->img_id);
            }
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('project_case')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-project-case-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'en_footer_menu' => $this->enFooterMenu,
            'projectCaseList' => $projectCaseList,
            'classifyName' => $classifyName
        ]);
    }

    public function enProjectCaseDetail(Request $request){
        $select = 'en_index';
        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $projectCase = EnProjectCases::whereId($id)->first();
        if($projectCase){
            $projectCase->thumb_img_url = FileManager::getImgUrl($projectCase->thumb_img_id);
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('project_case')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-detail',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'detail' => $projectCase,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyName
        ]);
    }

    public function enCharitableList(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        /** @var EnCharitableActivities $charitable */
        $charitableList = EnCharitableActivities::orderBy('sort','asc')->orderBy('created_at','desc')->paginate(9);
        if(count($charitableList) > 0){
            foreach($charitableList as $charitable){
                $charitable->img_url = FileManager::getImgUrl($charitable->img_id);
            }
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('charitable')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-charitable-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'en_footer_menu' => $this->enFooterMenu,
            'charitableList' => $charitableList,
            'classifyName' => $classifyName
        ]);
    }

    public function enCharitableDetail(Request $request){
        $select = 'en_index';
        $id = !is_null($request->get('id')) ? $request->get('id') : 0;

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $Charitable = EnCharitableActivities::whereId($id)->first();
        if($Charitable){
            $Charitable->thumb_img_url = FileManager::getImgUrl($Charitable->thumb_img_id);
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('charitable')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-detail',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'detail' => $Charitable,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyName
        ]);
    }

    public function enAboutDetail(Request $request){
        $select = 'en_index';

        $id = !is_null($request->get('id')) ? $request->get('id') : 0;
        if(!$id){
            $thisAbout = EnAboutUs::orderBy('sort','asc')->orderBy('created_at','desc')->first();
            if($thisAbout){
                $id = $thisAbout->id;
            }else{
                $id = 0;
            }
        }

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $aboutList = EnAboutUs::orderBy('sort','asc')->orderBy('created_at','desc')->get();

        $about = EnAboutUs::whereId($id)->first();
        if($about){
            $about->thumb_img_url = FileManager::getImgUrl($about->thumb_img_id);
        }

        $classifyName = Classify::whereLanguageType('en')->whereType('about')->first();
        if($classifyName){
            if($classifyName->img_id != 0){
                $classifyName->img_url = FileManager::getImgUrl($classifyName->img_id);
            }else{
                $classifyName->img_url = '';
            }
        }

        return view('en-about-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'aboutList' => $aboutList,
            'detail' => $about,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyName,
            'id' => $id
        ]);
    }

    public function enContact(Request $request){
        $select = 'en_index';

        //导航栏
        $sectionList = Classify::whereLanguageType('en')->whereIsNav(1)->whereStatus(1)->orderBy('sort','asc')->get();
        if(count($sectionList) > 0){
            foreach($sectionList as $section){
                if($section->type == 'environmental_section'){
                    $section->link_url = env("HOST_URL").'/en/en-environmental-list';
                }elseif($section->type == 'news'){
                    $section->link_url = env("HOST_URL").'/en/en-news-list';
                }elseif($section->type == 'project_case'){
                    $section->link_url = env("HOST_URL").'/en/en-project-case-list';
                }elseif($section->type == 'charitable'){
                    $section->link_url = env("HOST_URL").'/en/en-charitable-list';
                }elseif($section->type == 'about'){
                    $section->link_url = env("HOST_URL").'/en/en-about-detail';
                }elseif($section->type == 'online'){
                    $section->link_url = env("HOST_URL").'/en/en-contact';
                }
            }
        }

        $classifyOnline = Classify::whereLanguageType('en')->whereType('online')->first();
        if($classifyOnline){
            if($classifyOnline->img_id != 0){
                $classifyOnline->img_url = FileManager::getImgUrl($classifyOnline->img_id);
            }else{
                $classifyOnline->img_url = '';
            }
        }

        return view('en-contact-us-list',[
            'select' => $select,
            'sectionList' => $sectionList,
            'web_info' => $this->enWebInfo,
            'en_footer_menu' => $this->enFooterMenu,
            'classifyName' => $classifyOnline
        ]);
    }
}
